#include <RessourceManager.hh>

RessourceManager::RessourceManager()
{
    this->Images = *new std::map<std::string, sf::Image*>();
    this->Fonts = *new std::map<std::string, sf::Font*>();
}

RessourceManager::~RessourceManager()
{

}

void                RessourceManager::AddImage(const std::string &url)
{
    sf::Image       *img = new sf::Image();
    if (!img->LoadFromFile(url)){
        std::cout << "Fail to load : " << url << "\n";
        return;
    }
    else
        std::cout << "Load : " << url << "\n";
    this->Images.insert(std::pair<std::string, sf::Image*>(url, img));
}
void                RessourceManager::AddFont(const std::string &url)
{
    sf::Font       *font = new sf::Font();
    if (!font->LoadFromFile(url)){
        std::cout << "Fail to load : " << url << "\n";
        return;
    }
    else
        std::cout << "Load : " << url << "\n";
    this->Fonts.insert(std::pair<std::string, sf::Font *>(url, font));
}

const sf::Image &RessourceManager::GetImage(const std::string &url)
{
    std::map<std::string, sf::Image*>::iterator    it;
    for (it = this->Images.begin(); it != this->Images.end(); ++it){
        std::cout << it->first << ":" << url << std::endl;
        if (it->first == url)
            return *it->second;
    }
}

const sf::Font  &RessourceManager::GetFont(const std::string &url)
{
    std::map<std::string, sf::Font*>::iterator    it;
    for (it = this->Fonts.begin(); it != this->Fonts.end(); ++it)
        if (it->first == url)
            return *it->second;
}
